Add gdk_texture_save_to_tiff
authorMatthias Clasen <mclasen@redhat.com>
Tue, 7 Sep 2021 13:20:05 +0000 (09:20 -0400)
committerBenjamin Otte <otte@redhat.com>
Thu, 16 Sep 2021 22:25:22 +0000 (00:25 +0200)
This is a companion to gdk_texture_save_to_png, using
the tiff format, which will let us avoid lossy conversion
of HDR data, since we can store floating point data.

gdk/gdktexture.c
gdk/gdktexture.h

index 4176552df846c48c1b341bb7b7edf277a5547bce..7d1907be8d64f5372ac34bc57c9a2b0eea0da5aa 100644 (file)
@@ -748,3 +748,35 @@ gdk_texture_save_to_png_bytes (GdkTexture *texture)
 
   return gdk_save_png (texture);
 }
+
+/**
+ * gdk_texture_save_to_tiff:
+ * @texture: a `GdkTexture`
+ * @filename: (type filename): the filename to store to
+ *
+ * Store the given @texture to the @filename as a TIFF file.
+ *
+ * GTK will attempt to store data without loss.
+ * Returns: %TRUE if saving succeeded, %FALSE on failure.
+ *
+ * Since: 4.6
+ */
+gboolean
+gdk_texture_save_to_tiff (GdkTexture  *texture,
+                          const char  *filename)
+{
+  GBytes *bytes;
+  gboolean result;
+
+  g_return_val_if_fail (GDK_IS_TEXTURE (texture), FALSE);
+  g_return_val_if_fail (filename != NULL, FALSE);
+
+  bytes = gdk_save_tiff (texture);
+  result = g_file_set_contents (filename,
+                                g_bytes_get_data (bytes, NULL),
+                                g_bytes_get_size (bytes),
+                                NULL);
+  g_bytes_unref (bytes);
+
+  return result;
+}
index 7e7de473d8b465fa3bdf7dd93ea1d924f30aff82..8d46702b792ff387270b77fb440392354062df24 100644 (file)
@@ -93,6 +93,9 @@ gboolean                gdk_texture_save_to_png                (GdkTexture
                                                                 const char      *filename);
 GDK_AVAILABLE_IN_4_6
 GBytes *                gdk_texture_save_to_png_bytes          (GdkTexture      *texture);
+GDK_AVAILABLE_IN_4_6
+gboolean                gdk_texture_save_to_tiff               (GdkTexture      *texture,
+                                                                const char      *filename);
 
 G_END_DECLS